#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 100005;

int d[N], v[N], a[N], p[N];
int n, m, L, V;

namespace bf
{

}

namespace P20
{
    void solve()
    {
        int maxx = 0;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d%d%d", &d[i], &v[i], &a[i]);
        }
        for (int i = 1; i <= m; i++)
        {
            int x;
            scanf("%d", &x);
            maxx = max(maxx, x);
        }

        int cnt = 0;

        for (int i = 1; i <= n; i++)
            if (v[i] > V && maxx >= d[i]) cnt++;

        printf("%d %d\n", cnt, cnt == 0 ? m : m - 1);
    }
}

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);

    int T;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d%d%d%d", &n, &m, &L, &V);
        P20::solve();
    }
    return 0;
}
